package com.qf.service.Impl;

import com.qf.mapper.DeviceGatherMapper;
import com.qf.mapper.DeviceTypeMapper;
import com.qf.model.DeviceGather;
import com.qf.model.DeviceType;
import com.qf.page.PageResult;
import com.qf.page.QueryPageBean;
import com.qf.service.DeviceGatherService;
import com.qf.service.DeviceService;
import com.qf.service.DeviceTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class DeviceGatherServiceImpl implements DeviceGatherService {
    @Autowired
    private DeviceGatherMapper deviceGatherMapper;

    @Override
    public List<DeviceGather> findAll() {
        List<DeviceGather> list = deviceGatherMapper.getAll();
        return list;
    }

    @Override
    public PageResult findPage(QueryPageBean queryPageBean) {
        PageResult pageResult =new PageResult();
        Integer currentPage = queryPageBean.getCurrentPage();//当前页
        Integer pageSize = queryPageBean.getPageSize();//每页大小
        List<DeviceGather> page = deviceGatherMapper.findPage((currentPage-1)*pageSize,pageSize);
        long count = deviceGatherMapper.count();
        pageResult.setRows(page);
        pageResult.setTotal(count);
        return pageResult;
    }

    @Override
    public int addDeviceGather(DeviceGather deviceGather) {
        deviceGather.setUpdateTime(new Date());
        int row = deviceGatherMapper.insertDeviceGather(deviceGather);
        return row;
    }

    @Override
    public DeviceGather findById(int id) {
        DeviceGather deviceGather = deviceGatherMapper.findDeviceGather(id);
        return deviceGather;
    }

    @Override
    public int edit(DeviceGather deviceGather) {
        deviceGather.setUpdateTime(new Date());
        int row = deviceGatherMapper.update(deviceGather);
        return row;
    }

    @Override
    public int deleteById(Integer id) {
        int row = deviceGatherMapper.delDeviceGather(id);
        return row;
    }
}